package cn.zjj._02_xhr;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendCallback;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;

import java.nio.charset.StandardCharsets;

public class Xhr_Producer {


    public static void main(String[] args) throws Exception{
        //1.准备生产者对象
        DefaultMQProducer producer = new DefaultMQProducer("xhr_producer_group");
        //2.设置nameserver 注册中心: 管家,调度,需要什么去他这儿,但是它不做事
        producer.setNamesrvAddr("localhost:9876");
        //3.启动
        producer.start();
        //4.创建消息对象,发送消息    topic:主题名,消费时需要主题名才能消费该消息
        Message message = new Message("xhr","hellojava","你好,世界!".getBytes(StandardCharsets.UTF_8));
        producer.send(message, new SendCallback() {
            @Override
            public void onSuccess(SendResult sendResult) {
                System.out.println("信息消费成功!"+sendResult);
            }

            @Override
            public void onException(Throwable throwable) {
                throwable.printStackTrace();
                System.out.println("信息消费失败");
            }
        });
        System.out.println("如果先打印此句就代表先执行了后面的,xhr体现");


    }
}
